Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create utils and Jupiter extension to reset Logback #468

Merged
merged 16 commits into from
Feb 10, 2024

Conversation

sleberknight
Copy link
Member

@sleberknight sleberknight commented Feb 9, 2024

  • Add LogbackTestHelpers utility class. This provides static utilities to reset Logback.
  • Add LogbackTestHelper. This provides instance-based utilities to reset Logback.
  • Add ResetLogbackLoggingExtension, a Jupiter extension to reset Logback after all tests have run.
  • Add UncheckedJoranException, which wraps the checked Logback JoranException.
  • Update several tests that use Dropwizard extensions to use ResetLogbackLoggingExtension to restore logging.

Closes #460
Closes #461

* Add LogbackTestHelpers utility class. This provides utilities
  to reset Logback.
* Add ResetLogbackLoggingExtension, a Jupiter extension to
   reset Logback after all tests have run.
* Add UncheckedJoranException, which wraps the checked
  Logback JoranException.
* Update several tests that use Dropwizard extensions to use
   ResetLogbackLoggingExtension to restore logging.

Closes #460
Closes #461
* Remove redundant throws clauses
* Replace duplicate code in InMemoryAppenderExtension with
  call to LogbackTestHelpers#resetLogback
* Make visibility of Dropwizard Configuration classes in
  several tests the same as the Application class
* Suppress "throwable not thrown" in UncheckedJoranExceptionTest
* Remove public modifier from LogbackTestHelpersIntegrationTest
* Fix javadoc typo and grammar in LogbackTestHelpersIntegrationTest
* Sonar java:S3551 - make UncheckedJoranException#getCause synchronized
  to math the synchronization of Throwable#getCause. While I get what
  Sonar is saying, I'm not entirely convinced this is really an issue.
  For example, why does java.io.UncheckedIOException override getCause
  but NOT make it synchronized? But go ahead and make Sonar happy...
* Make resetLogback() try logback-test.xml, then logback.xml as fallback
* Add varargs argument to resetLogback so that it accepts a primary
  location, and optionally fallback locations
All it does right now is validate withLogbackConfigFilePath
* Make logbackConfigFilePath final in ResetLogbackLoggingExtension
* Add test that verifies default and custom config locations
The reason to do this is to provide more flexibility. Unless
a custom Logback config file is provided, use the
LogbackTestHelpers.resetLogback() method which attempts
both logback-test.xml with logback.xml as a fallback.
Add LogbackTestHelper which mainly delegates to LogbackTestHelpers.
It adds a new method, resetLogbackWithDefaultOrConfig, which removes
the duplicate conditional logic in the InMemoryAppenderExtension and
the ResetLogbackLoggingExtension. It also allows for mocking in
tests of the Logback reset mechanisms and extensions.
Since it gets mocked, it's never tested. So, this tests it.

And hey, it could theoretically break if someone changed it
to return null!
This method is mocked in other tests, so is never exercised.
Test the delegation to LogbackTestHelpers by passing arguments
that don't exist, and validating the exception we get. Kind
of invasive but gets the job done without actually resetting
Logback, which we generally want to avoid.
@sleberknight sleberknight self-assigned this Feb 10, 2024
@sleberknight sleberknight changed the title Create utils and Jupter extension to reset Logback Create utils and Jupiter extension to reset Logback Feb 10, 2024
Copy link

@sleberknight sleberknight marked this pull request as ready for review February 10, 2024 22:37
@sleberknight sleberknight merged commit 04f3715 into master Feb 10, 2024
5 checks passed
@sleberknight sleberknight deleted the logback-reset-utilities branch February 10, 2024 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants